package com.cy.dda.web.front.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cy.dda.model.Result;
import com.cy.dda.model.ao.user.UserUpdatePasswordAO;
import com.cy.dda.model.vo.user.UserIndexCasesInfoVO;
import com.cy.dda.model.vo.user.UserIndexCollectionRecordInfoVO;
import com.cy.dda.model.vo.user.UserIndexInfoVO;
import com.cy.dda.service.user.UserService;
import com.cy.dda.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 前台-用户模块
 *
 * @author: tanyilin
 * @create: 2018年11月12日 下午4:02:33
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "前台-用户模块")
public class UserController extends BaseController {

	@Autowired
	private UserService userService;
	
	@ApiOperation("前台用户首页信息")
	@GetMapping("/index/info")
	public Result<UserIndexInfoVO> selectUserIndexInfoVO() {
		Long userId = this.getUser().getUserId();
		UserIndexInfoVO userIndexInfoVO = userService.selectUserIndexInfoVO(userId);
		return ok("", userIndexInfoVO);
	}
	
	@ApiOperation("前台用户首页新派委案信息")
	@GetMapping("/index/cases/info")
	public Result<List<UserIndexCasesInfoVO>> selectUserIndexCasesInfoVO() {
		Long userId = this.getUser().getUserId();
		List<UserIndexCasesInfoVO> list = userService.selectUserIndexCasesInfoVO(userId);
		return ok("", list);
	}
	
	@ApiOperation("前台用户首页最近催收记录")
	@GetMapping("/index/collection/record/info")
	public Result<List<UserIndexCollectionRecordInfoVO>> selectUserIndexCollectionRecordInfoVO() {
		Long userId = this.getUser().getUserId();
		List<UserIndexCollectionRecordInfoVO> list = userService.selectUserIndexCollectionRecordInfoVO(userId);
		return ok("", list);
	}

	@ApiOperation("修改密码")
	@PostMapping("/update/password")
	public Result updatePassword(@Validated UserUpdatePasswordAO updatePasswordAO, BindingResult bindingResult) {
		this.checkError(bindingResult);
		userService.updatePassword(this.getUser().getUserId(), updatePasswordAO.getOldPassword(), updatePasswordAO.getNewPassword());
		return ok();
	}
}
